iconhelper: Try to avoid some save/restore calls
authorTimm Bäder <mail@baedert.org>
Sat, 6 Jul 2019 10:57:36 +0000 (12:57 +0200)
committerTimm Bäder <mail@baedert.org>
Sun, 7 Jul 2019 05:24:00 +0000 (07:24 +0200)
GtkImage already does something similar so we often end up with 0/0
here. Avoid the save()/restore() calls in GtkSnapshot in that case.

gtk/gtkiconhelper.c

index 5698b2bdbc6fd9e75de1146f7f9863b107098154..a7cf18220f116465c76f82d3ac9804f83fec9b11 100644 (file)
@@ -227,19 +227,35 @@ gtk_icon_helper_paintable_snapshot (GdkPaintable *paintable,
         h = MIN (h, height);
         x = (width - w) / 2;
         y = (height - h) / 2;
-        gtk_snapshot_save (snapshot);
-        gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
-        gtk_css_style_snapshot_icon_paintable (style,
-                                               snapshot,
-                                               self->paintable,
-                                               w, h,
-                                               self->texture_is_symbolic);
-        gtk_snapshot_restore (snapshot);
+
+        if (x  != 0 || y != 0)
+          {
+            gtk_snapshot_save (snapshot);
+            gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
+            gtk_css_style_snapshot_icon_paintable (style,
+                                                   snapshot,
+                                                   self->paintable,
+                                                   w, h,
+                                                   self->texture_is_symbolic);
+            gtk_snapshot_restore (snapshot);
+          }
+        else
+          {
+            gtk_css_style_snapshot_icon_paintable (style,
+                                                   snapshot,
+                                                   self->paintable,
+                                                   w, h,
+                                                   self->texture_is_symbolic);
+
+          }
+
       }
       break;
 
-    case GTK_IMAGE_PAINTABLE:
     case GTK_IMAGE_EMPTY:
+      break;
+
+    case GTK_IMAGE_PAINTABLE:
     default:
       {
         double image_ratio = (double) width / height;
@@ -269,14 +285,25 @@ gtk_icon_helper_paintable_snapshot (GdkPaintable *paintable,
         x = floor (width - ceil (w)) / 2;
         y = floor (height - ceil (h)) / 2;
 
-        gtk_snapshot_save (snapshot);
-        gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
-        gtk_css_style_snapshot_icon_paintable (style,
-                                               snapshot,
-                                               self->paintable,
-                                               w, h,
-                                               self->texture_is_symbolic);
-        gtk_snapshot_restore (snapshot);
+        if (x != 0 || y != 0)
+          {
+            gtk_snapshot_save (snapshot);
+            gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
+            gtk_css_style_snapshot_icon_paintable (style,
+                                                   snapshot,
+                                                   self->paintable,
+                                                   w, h,
+                                                   self->texture_is_symbolic);
+            gtk_snapshot_restore (snapshot);
+          }
+        else
+          {
+            gtk_css_style_snapshot_icon_paintable (style,
+                                                   snapshot,
+                                                   self->paintable,
+                                                   w, h,
+                                                   self->texture_is_symbolic);
+          }
       }
       break;
     }